/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	RenderEntryLight.cpp
*
*	Comments	-	See RenderEntryLight.h
*
**************************************************************************************/

#include "../Include/RenderEntryLight.h"
#include "../Include/ComponentLight.h"
#include "../Include/RenderEntryModel.h"
#include "../Include/Actor.h"
#include "../Include/Model.h"

namespace Pulse
{
	RenderEntryLight::RenderEntryLight( void )
		: m_pParams( PSX_NULL ), m_pLightModel( PSX_NULL )
	{

	}

	RenderEntryLight::~RenderEntryLight( void )
	{
		Clear();
	}

	void RenderEntryLight::SetLightModel( Model *pLightModel )
	{
		PSX_SafeRelease( m_pLightModel );
		m_pLightModel = pLightModel;

		if ( pLightModel )
			pLightModel->AddRef();
	}

	void RenderEntryLight::Clear( void )
	{
		m_pParams = PSX_NULL;
		PSX_SafeRelease( m_pLightModel );
		m_modelRenderEntries.ClearRenderEntries();
	}

	void RenderEntryLight::Execute( GraphicsPipeline *pPipeline )
	{
		m_pParams->BindParameters();

		const SIZE_T numEntries = m_modelRenderEntries.GetNumEntries();
		RenderEntry **pEntries = m_modelRenderEntries.GetRenderEntries();
		RenderEntry *pEntry;

		for ( SIZE_T i = 0; i < numEntries; ++i )
		{
			pEntry = pEntries[i];

			pEntry->PreExecute( pPipeline );
			pEntry->Execute( pPipeline );
			pEntry->PostExecute( pPipeline );
		}
	}
}